package main

import (
	"context"
	"fmt"
	"github.com/apache/rocketmq-client-go/v2"
	"github.com/apache/rocketmq-client-go/v2/primitive"
	"github.com/apache/rocketmq-client-go/v2/producer"
	"os"
)

func main() {
	p, _ := rocketmq.NewProducer(
		producer.WithNameServer([]string{"127.0.0.1:9876"}),
		producer.WithRetry(2),
	)
	err := p.Start()
	if err != nil {
		fmt.Printf("start producer error: %s\n", err.Error())
		os.Exit(1)
	}
	defer p.Shutdown()

	//orderID := "12345699999999999" // 假设这是订单ID

	for i := 1000; i < 1001; i++ {
		orderID := fmt.Sprintf("OrderTopic ---- %d", i)
		msg := &primitive.Message{
			Topic: "OrderTopicDead",
			Body:  []byte(orderID),
		}
		// 设置延迟等级，这里假设我们有一个对应的延迟等级
		msg.WithDelayTimeLevel(2)

		_, err = p.SendSync(context.Background(), msg)
		if err != nil {
			fmt.Printf("send message error: %s\n", err)
		} else {
			fmt.Printf("send message success, orderID: %s\n", orderID)
		}
	}

}
